package com.mhuang.module.common.start;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.mhuang.module.job.JobService;
import com.mhuang.module.wechat.config.WechatConfig;
import com.mhuang.quartz.service.SchedulerJobService;

/**
 * 
 * @Package: com.mhuang.module.common.start
 * @Description Spring加载完成后执行-->
 * @author huang.miao
 * @date 2017年2月8日 下午4:59:03  
 * @since 1.0.0
 * @group skiper-opensource
 */
public class StartupListener implements ApplicationListener<ContextRefreshedEvent>{

	@Autowired
    private WechatConfig wechatConfig;
	
	@Autowired
    private SchedulerJobService  schedulerJobService;
	
	@Autowired
	private JobService jobService;
	
	public void onApplicationEvent(ContextRefreshedEvent evt) {
		if (evt.getApplicationContext().getParent() == null) {//所有都执行完后执行配置
			
			System.out.println("loading wechatConfig file..");
			wechatConfig.init();
			System.out.println("load ok wechatConfig");
			
			System.out.println("loading SchedulerJob task..");
			schedulerJobService.init(jobService.getListEntitys());
			System.out.println("loading SchedulerJob task ok");
		}
	}
}
